<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="文件管理"></uni-navbar></view>

		<view class="search-view"><u-search class="search-input" @search="search" @custom="search"></u-search></view>

		<view class="list-box" :style="{ background: loading == 'nodata' ? 'none' : '#fff' }">
			<view class="list-info_01" v-for="(item, index) of fileList" :key="item.id" @click="$showLine(item)">
				<view class="info-title">{{ item.name }}</view>
				<view class="info-btm">
					<view class="btm-left clamp">
						<text class="left-name">{{ item.createBy }}</text>
						<text class="left-time">{{ item.createTime }}</text>
					</view>
					<view class="btm-right"><view class="right-type">预览</view></view>
				</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			id: '',
			fileList: [],

			name: '',
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;

				this.pageNum = 1;
				this.pageSize = 10;
				this.nodeStatus = 0;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.nodeStatus == 0) {
				this.nodeStatus = '';
			}

			let data = {
				clientCode: this.clientCode,
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				name: this.name,
				remark2: this.nodeStatus
			};
			this.$request('/huiyihuodong/hyhd-meeting/fileList', data, {
				load: true
			}).then((res) => {
				let count = 0;
				if (type != 'add') {
					uni.stopPullDownRefresh();
					this.fileList = [];
				}
				this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
				this.pageNum = this.pageNum + 1;
				this.fileList = this.fileList.concat(res.data.records);
				this.loaded = true;
				if (this.fileList.length <= 0) {
					this.loading = 'nodata';
				}
			});
		},
		search(e) {
			this.name = e;
			this.loadData('refresh');
		},
		type(e) {
			this.nodeStatus = e;
			this.loadData('refresh');
		},
		navTo(item) {}
	}
};
</script>

<style lang="scss">
.list-box {
	padding: 0 30rpx;
	background-color: #fff;
}
</style>
